package org.fuxian.web.controller;

import org.fuxian.domain.MyEmp;
import org.fuxian.service.IMyEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class MyEmpController {

    @Autowired
    private IMyEmpService myempService;

    @RequestMapping("/findByEname")
    @ResponseBody
    public MyEmp findByEname(String ename, HttpSession session) {

        MyEmp emp = myempService.findByEname(ename);
        if (emp != null && emp.getEname() != null && emp.getEpsw() != null) {
           return emp;
        }
        return null;
    }


    @RequestMapping("/login")
    @ResponseBody
    public MyEmp login(MyEmp emp, HttpSession session) {

        if (emp != null && emp.getEname() != null && emp.getEpsw() != null) {
            emp = myempService.login(emp);
            session.setAttribute("LOGIN_USER", emp);
        }

        return emp;
    }

    @RequestMapping("/redirect")
    public String login_success(String page, HttpSession session) {
//        MyEmp emp = (MyEmp) session.getAttribute("LOGIN_USER");
//        if (emp == null) {//未登录
//            return "redirect:/index.jsp";
//        }
        return page;
    }
}
